package com.game.commons.configuration.transformers;

import java.lang.reflect.Field;

import com.game.commons.configuration.PropertyTransformer;
import com.game.commons.configuration.TransformationException;


/**
 * 字符串转换成class类型
 * 注：字符串是指定类的路径
 * @author 杜祥
 * @create 2013-6-29
 */
public class ClassTransformer implements PropertyTransformer<Class<?>>
{
	public static final ClassTransformer	SHARED_INSTANCE	= new ClassTransformer();

	@Override
	public Class<?> transform(String value, Field field) throws TransformationException
	{
		try
		{
			return Class.forName(value, false, getClass().getClassLoader());
		}
		catch(ClassNotFoundException e)
		{
			throw new TransformationException("Cannot find class with name '" + value + "'");
		}
	}
}
